import QtQuick 2.0
import Qt.labs.folderlistmodel 2.1
Item {

    GridView {
        model: folderModel
        delegate: panelSimpleDelegate
        clip: true
        focus: true
        width: 100
        height: 40

        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        anchors.top: parent.top

        header: Rectangle {
            width: 25
            height: 25

            Image {
                anchors.fill: parent
                source: "up_icons.png"
            }

            //Text {
            //text: "Up"
            MouseArea {
                anchors.fill: parent
                onClicked: {
                    folderModel.folder = folderModel.parentFolder
                }
            }
        }


        FolderListModel {
            id: folderModel
            //  nameFilters: ["*.qml"]
            folder: 'file:///'   //'/sys'           //"file:///c:"
           // showDotAndDotDot: true



            onFolderChanged: {
                console.log("folder > ", folderModel.folder);

            }
            onParentFolderChanged: {
                console.log("parentFolder > ", folderModel.parentFolder);
            }
        }

        Component {
           id: panelSimpleDelegate
          Column {
               spacing: 2

               Rectangle {
                   id: icon
                   color: "#e48585"
                   border.color: "black"
                   gradient: Gradient {
                       GradientStop {
                           position: 0.19;
                           color: "#a1f763";
                       }
                       GradientStop {
                           position: 1.00;
                           color: "#ffffff";
                       }
                   }

                   width: 30
                   height: 30

                   MouseArea {
                       anchors.fill: parent
                       hoverEnabled: true

                       onClicked: {
                           var f = folderModel.folder.toString();

                           console.log(typeof(f));
                           console.log('fileIsDir' + '>>>' + fileIsDir);



                           if(f.substring(f.length-1) != "/")
                               //                    if(f.right(1) != "/")
                           {
                               f += "/";
                           }
                           f += fileName;
                           folderModel.folder = f;
                       }
                   }
               }

                    Text {
                        id: fileNameText
                        clip: true
                        width: 100
                        color: "black"
                        text: fileIsDir ? '[' + fileName + ']' : fileName
                        font.family: "Plantagenet Cherokee"
                        font.bold: fileIsDir ? true : false

                        styleColor: "#751ed1"
                        font.pointSize: 12



                        MouseArea {
                            anchors.fill: parent
                            hoverEnabled: true

                            onClicked: {
                                var f = folderModel.folder.toString();

                                console.log(typeof(f));
                                console.log('fileIsDir' + '>>>' + fileIsDir);



                                if(f.substring(f.length-1) != "/")
                                    //                    if(f.right(1) != "/")
                                {
                                    f += "/";
                                }
                                f += fileName;
                                folderModel.folder = f;
                            }
                        }

                    }


                }
            }
        }

}


